home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
System
/
flow.c
< prev
next >
Wrap
Text File
|
1986-04-19
|
4KB
|
225 lines
/* ----------------- flow -----------------
*
* Make the Mac screen flow away.
* Written in Aztec C.
*
* Author: Fons Rademakers, Nikhef-h/CERN
* Version: 29-oct-1985
* Revision:
*
*/
#asm
main
dc.w $6400 ;ctl-enable, need time and locked in mem.
dc.w 0 ;update as often as possible
dc.w $0001 ;don't react on any specific event
dc.w 0 ;no menu
dc.w open_-main ;open routine
dc.w nop_-main ;prime routine
dc.w control_-main ;control routine
dc.w nop_-main ;status routine
dc.w close_-main ;close routine
title_
dc.b 4
dc.b "Flow"
ds 0 ;for alignment
public _Uend_,_Dorg_,_Cend_
save_
lea main+(_Uend_-_Dorg_)+(_Cend_-main),a4 ;set up globals
move.l a0,Pbp_ ;save pb pointer
move.l a1,Dp_ ;save DCE pointer
rts
restore_
move.l Pbp_,a0
rts
#endasm
#define _DRIVER
#define SMALL_MEM
#include <quickdraw.h>
#include <memory.h>
#undef SMALL_MEM
#include <event.h>
#include <pb.h>
#include <desk.h>
#define NULL (0L)
#define BASE1 512 /* Mac screen size in x direction */
#define BASE2 342 /* Mac screen size in y direction */
#define SP (*(struct storage **)Dp->dCtlStorage)
DCEPtr Dp;
ParmBlkPtr Pbp;
Rect wind_rect = {0, 0, 0, 0};
struct storage {
GrafPtr flowport; /* the flow grafport */
Pattern black;
short portspace[54]; /* space for the flowport */
short y;
};
open()
{
register WindowPtr wp;
register struct DCE *dp;
register struct storage *sp;
extern char title[];
struct windowpeek {
GrafPort port;
int windowKind;
};
short x, i;
save();
dp = Dp;
if (dp->dCtlWindow == NULL) {
HLock(dp->dCtlStorage = NewHandle((long) sizeof(struct storage)));
sp = SP;
/* create an invisible window */
dp->dCtlWindow =
wp = NewWindow(NULL, &wind_rect, title, FALSE, plainDBox, -1L, FALSE,
NULL);
((struct windowpeek *)wp)->windowKind = dp->dCtlRefNum;
/* allocate space for new flowport */
&sp->flowport->device = sp->portspace;
OpenPort(sp->flowport);
/* set start y value */
sp->y = 0;
/* black pattern */
StuffHex(sp->black, "\PFFFFFFFFFFFFFFFF");
/* set the background pattern to black */
BackPat(sp->black);
HUnlock(dp->dCtlStorage);
}
restore();
return(0);
}
close()
{
register struct DCE *dp;
save();
dp = Dp;
/* get rid of the allocated space for the window */
DisposeWindow(dp->dCtlWindow);
dp->dCtlWindow = NULL;
DisposHandle(dp->dCtlStorage);
restore();
return(0);
}
nop()
{
return(0);
}
control()
{
register struct DCE *dp;
register struct storage *sp;
short x, i;
short xdest, ydest;
Rect destrect;
RgnHandle dummyrgn;
save();
dp = Dp;
HLock(dp->dCtlStorage);
sp = SP;
switch (Pbp->u.cp.csCode) {
case accRun: /* time to flow the screen */
SetPort(sp->flowport);
if (sp->y <= BASE2) {
for (i = 1; i <= 7; i++) {
dummyrgn = NewRgn();
x = jrand(BASE1);
SetRect(&destrect, x, sp->y, min(x+150, BASE1), rand(sp->y, BASE2));
xdest = rand(-3, 3);
ydest = rand(1, 4);
ScrollRect(&destrect, xdest, ydest, dummyrgn);
DisposeRgn(dummyrgn);
}
MoveTo(0, sp->y);
LineTo(BASE1, sp->y);
sp->y++;
} else
sp->y = 0;
break; /* end case */
}
HUnlock(dp->dCtlStorage);
restore();
return(0);
}
/* Return random number uniformly distributed on [min,max].
* Note that Random() delivers a value on [-32768,32767]. */
rand(min, max)
int min, max;
{
float ran;
ran = (max - min + 1.0)*(float)abs(Random())/32768.0 + min;
return((ran < 0) ? --ran : ran);
}
/* Return random number, on base [0, base>, with quadratic emphasis
* round base/2. */
jrand(base)
int base;
{
float x, ran;
x = (float)abs(Random())/32768.0; /* random number uniformly on [0,
1> */
ran = 2.0*(float)base*x*(1.0 - x);
if (x >= 0.5)
ran = (float)base - ran;
return(ran);
}
/* Return absolute value of an integer */
abs(n)
int n;
{
return((n > 0) ? n : -n);
}
/* Return the max integer */
max(a, b)
int a, b;
{
return((a > b) ? a : b);
}
/* Return the min integer */
min(a, b)
int a, b;
{
return((a < b) ? a : b);
}